package com.frost.system.controller.exam;

import com.frost.common.core.controller.BaseController;
import com.frost.common.core.domain.R;
import com.frost.common.core.domain.TableDataInfo;
import com.frost.system.domain.exam.dto.ExamAddDTO;
import com.frost.system.domain.exam.dto.ExamQueryDTO;
import com.frost.system.domain.exam.dto.ExamQuestionAddDTO;
import com.frost.system.domain.exam.vo.ExamDetailVO;
import com.frost.system.domain.exam.vo.ExamVO;
import com.frost.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理接口")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @GetMapping("/list")
    @Operation(summary = "竞赛列表")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        List<ExamVO> list = examService.list(examQueryDTO);
        return getTableList(list);
    }

    @PostMapping("/add")
    @Operation(summary = "新增竞赛", description = "不包含题目的新增竞赛")
    public R<String> add(@RequestBody ExamAddDTO examAddDTO) {
        return R.OK(examService.add(examAddDTO));
    }

    @PostMapping("/question/add")
    @Operation(summary = "新增竞赛", description = "包含题目的新增竞赛")
    public R<Void> questionAdd(@RequestBody ExamQuestionAddDTO examQuestionAddDTO) {
        return toR(examService.questionAdd(examQuestionAddDTO));
    }

    @GetMapping("/detail")
    @Operation(summary = "竞赛详情", description = "查询竞赛的详细信息")
    public R<ExamDetailVO> detail(Long examId) {
        return R.OK(examService.detail(examId));
    }
}
